package cn.edu.scau.vsac.controller;

import cn.edu.scau.vsac.common.ResultData;
import cn.edu.scau.vsac.entity.Activity;
import cn.edu.scau.vsac.service.ActivityService;
import cn.edu.scau.vsac.util.HostHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Tag(name = "活动")
@RequestMapping("activity")
public class ActivityController {
    @Autowired
    ActivityService activityService;
    @Autowired
    HostHolder hostHolder;

    @Operation(summary = "新增活动")
    @RequestMapping(path = "/create", method = RequestMethod.POST)
    public ResultData create(@RequestBody Activity activity) {
        activity.setCreateBy(hostHolder.getUser().getUserId());
        activityService.create(activity);
        return ResultData.success("");
    }

    @Operation(summary = "查询所有")
    @RequestMapping(path = "/query", method = RequestMethod.GET)
    public ResultData<List<Activity>> query() {
        List<Activity> list = activityService.list();
        return ResultData.success(list);
    }


}
